#ifndef _THREAD_POOL_H
#define _THREAD_POOL_H 


#include <pthread.h>

typedef unsigned short u16;

typedef struct 
{
    void *(*func)(void * );//一个任务（某个函数）
    void * arg; //该任务的参数
}Task, *Taskp;



typedef struct
{
  //poll's basic 3 struct: 1--task_queue; 2--threads_arr(store tid); 3--threads_manager thread
  Task *tasks; //顺序-循环-队列（非链表）
  //about tasksqueue
  u16 q_front; //pointer to the first member rate +++(Worker)
  u16 q_rear; //pointer to the last member  rate +(Client ?)
  u16 task_num; //(LOCK)rate +++(Workerm Client)
  pthread_t *threads;
  pthread_t manager;

  //poll's task_queue & thread_arr & threads_manager's attributes
  //task queue about: max_taskque  
  u16 max_task;//==taskQ_cap
  //thread about: max_thrd min_thrd
  u16 max_thrd;
  u16 min_thrd; 
 
  //manager about:(for manager)
  //u16 max_idle_tick;
  u16 live_thrd_num; //(LOCK)rate +(Manager?)
  u16 busy_thrd_num; //(LOCK)rate +++(Worker)
  u16 waitexit_thrd_num;//(LOCK)rate +(Worker, Manager)

  //about lock and cond 
  pthread_mutex_t pool_mutex;
  pthread_mutex_t busy_mutex;
  pthread_cond_t pool_cond_notfull;
  pthread_cond_t pool_cond_notemp;

  //other info:
  int shutdown; //=0 working; =1 shutdown

}Thread_Pool, *Thread_Poolp;






#endif 